﻿using System;
using System.Collections.Generic;
using System.Text;
using EShop.Common;

namespace EShop.DAL
{
    public class DbOperationDAL:BaseDAL
    {
        public bool Backup(string strBackupPath)
        {
            //= "BACKUP DATABASE " + cbbData.Text.Trim() + " TO DISK = '" + filepath + "'";
            string strSQL = "BACKUP DATABASE eShop TO DISK ='" + strBackupPath + "'";
            try
            {
                DbHelper.ExecuteNonQuerySQL(strSQL);
                return true;
            }
            catch(Exception ex)
            {
                log.Write("数据备份失败，详细信息为：" + ex.Message);
                return false;
            }
        }

        public bool Restory(string strRestorePath)
        {
            string SqlStr2 = "use master restore database eShop from disk='" + strRestorePath + "'";
            string single = "exec sp_dboption 'eShop','Single user',true  " + SqlStr2 + "WITH REPLACE";
            single += "  exec sp_dboption 'eShop','Single user',false";
            try
            {
                DbHelper.ExecuteNonQuerySQL(single);
                return true;
            }
            catch (Exception ex)
            {
                log.Write("数据恢复失败，详细信息为：" + ex.Message);
                return false;
            }
        }
    }
}
